package solutions.ferpa.ztest.intf;

import br.com.telescope.adsrt.lib.AdsException;
import br.com.telescope.t2.ModuleNavigator;
import br.com.telescope.t2.ServiceNavigation;
import br.com.telescope.t2.exception.ApplicationRuntimeException;
import solutions.ferpa.ztest.ent.EntItemInstrucao;

public class ModIteminst extends ModuleNavigator {
    
    public ModIteminst() {
        
        setGlobalName("ZTEST.MOD_ITEMINST");
        setInitialService(CadItemInstrucao.class, "LIST");
        
        addNavigation((new ServiceNavigation())
                .id("20842314")
                .name("MASTER")
                .label("Item da instrução")
                .destination(CadItemInstrucao.class)
                .feature("VIEW")
                .parameterName("A_ID")
                );
        addNavigation((new ServiceNavigation())
                .id("20842325")
                .name("DET_ITEM")
                .label("Detalhamento do item")
                .destination(CadDetalheItemInstrucao.class)
                .feature("LIST")
                .parameterName("P_ID_ITEM_INSTRUCAO_PAI")
                );
    }
    
    @Override
    public void preDisplay() {
        try {
            desabilitarGuiasDetalhamento();
        } catch (AdsException ex) {
            throw new ApplicationRuntimeException(ex);
        }
    }
    
    /**
     * Desabilitar guias de detalhamento do item.
     */
    private void desabilitarGuiasDetalhamento() throws AdsException {
        // <user-code id="20976617" parentId="20976598" hashcode="22260043" length="315">
        // import solutions.ferpa.ztest.ent.EntItemInstrucao;
        
        Long id = Long.parseLong(getContextValue());
        EntItemInstrucao item = new EntItemInstrucao(ctx);
        item.findById(id);
        if (item.findTipoItemInstrucao().valueOfCaracteristicaItemInstrucao().equals("E")) {
            getGuideByName("DET_ITEM").setVisible(false);
        }
        
        // </user-code>
    }
}
